﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace CaptureImageMergeSys
{
    public partial class MainPanel : Form
    {
        private VideoPanel m_VideoPanel;
        public MainPanel()
        {
            InitializeComponent();

            LoadImagePanels();
            LoadVideoPanels();
            
        }

        private void MainPanel_Load(object sender, EventArgs e)
        {

        }
        private void LoadVideoPanels()
        {
            m_VideoPanel = new VideoPanel();
            m_VideoPanel.Dock = System.Windows.Forms.DockStyle.Fill;
            m_VideoPanel.Parent = WorkPanelSplitter.Panel1;
            WorkPanelSplitter.Panel1.Controls.Add(m_VideoPanel);
            WorkPanelSplitter.SplitterDistance = m_VideoPanel.Height;
            m_VideoPanel.AutoScroll = false;
            m_VideoPanel.Show();
        }
        private void LoadImagePanels()
        {
            ImagePanel objImagePanel = new ImagePanel();
            objImagePanel.Dock = System.Windows.Forms.DockStyle.Fill;
            objImagePanel.Parent = WorkPanelSplitter.Panel2;
           
            objImagePanel.Width = WorkPanelSplitter.Panel1.Width;
            objImagePanel.Parent = WorkPanelSplitter.Panel2;
            WorkPanelSplitter.Panel2.Controls.Add(objImagePanel);
            WorkPanelSplitter.SplitterDistance = 0;
            objImagePanel.AutoScroll = false;
            objImagePanel.Show();
            WorkPanelSplitter.Panel2.Hide();
           // WorkPanelSplitter.Panel2.Hide();
        }
        private void MainPanel_Resize(object sender, EventArgs e)
        {

        }

        private void StartWorkBtn_Click(object sender, EventArgs e)
        {

            if (m_VideoPanel.StartVideo())
            {
                UpdateBtnStatusWhenStartWork();
            }
            else
            {
                MessageBox.Show("Failed to Start Video!", "ERROR");
            }
        }

        private void StopWorkBtn_Click(object sender, EventArgs e)
        {
            if (m_VideoPanel.StopVideo())
            {
                UpdateBtnStatusWhenStopWork();
            }
            else
            {
                MessageBox.Show("Failed to Stop Video!", "ERROR");
            }
        }

        private void VideoAndImageSwitchBtn_Click(object sender, EventArgs e)
        {
            if (m_bSystemWorkInImageMode)
            {
                SwitchToWorkInVideoMode();
            }
            else
            {
                SwitchToWorkInImageMode();
            }
        }

        private void UpdateBtnStatusWhenStartWork()
        {
            StartWorkBtn.Enabled = false;
            StopWorkBtn.Enabled = true;
            VideoAndImageSwitchBtn.Enabled = true;
        }
        private void UpdateBtnStatusWhenStopWork()
        {
            StartWorkBtn.Enabled = true;
            StopWorkBtn.Enabled = false;
            VideoAndImageSwitchBtn.Enabled = false;
        }
        private void InitializeWorkPanelBtnStatus()
        {
            StartWorkBtn.Enabled = true;
            StopWorkBtn.Enabled = false;
            VideoAndImageSwitchBtn.Enabled = false;
        }
        private void SwitchToWorkInImageMode()
        {
            m_bSystemWorkInImageMode = true;
            
            WorkPanelSplitter.SplitterDistance = 0;
           
            WorkPanelSplitter.Panel1.Hide();
            WorkPanelSplitter.Panel2.Show();
        }
        private void SwitchToWorkInVideoMode()
        {
            m_bSystemWorkInImageMode = false;
            WorkPanelSplitter.SplitterDistance = WorkPanelSplitter.Panel1.Controls[0].Height;
            WorkPanelSplitter.Panel1.Show();
            WorkPanelSplitter.Panel2.Hide();



        }
        private bool m_bSystemWorkInImageMode = false;
    }
}
